package webday03;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoJsp extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//resp.sendRedirect("http://www.baidu.com");
	//在一个页面上显示用户的IP地址和访问时间
		String ip=req.getRemoteAddr();
		//访问的时间
		Date d=new Date();
		
		//时间格式化
		DateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date=formatter.format(d);
		
		//在servlet跳到jsp
		//转发
		req.setAttribute("message", ip+"&nbsp&nbsp"+date);
		req.getRequestDispatcher("NewFile.jsp").forward(req, resp);
		
			
		// 往浏览器输出内容
//		PrintWriter writer = resp.getWriter();
//					
//		writer.write("<html>");
//		writer.write("<body>");
//		//加入IP与时间
//		writer.write("<h3>"+ip+date+"</h3>");
//		writer.write("</body>");
//		writer.write("</html>");
		//读requst的内容
		
	}
}
